//constante
L = 30;
//--------------------------
function [g] = rad2gr(r)
	g = (180*r)/%pi
endfunction;
function [r] = gr2rad(g)
	r = (g*%pi)/180
endfunction;
function [r2] = supr(r)
  r2 = %pi - r
endfunction;
function [g2] = supg(g)
  g2 = 180 - g
endfunction;
//--------------------------
function [y] = rn1(x)
	y = (sqrt(3)/3) * x
endfunction;
function [y] = rn2(x)
	y = [-(sqrt(3)/3) * x] + (sqrt(3)/3)*L
endfunction;
//--------------------------
function [y] = r11(x,m11,teta)
	y = m11*x - [ L/4*( 3*m11 - sqrt(3) ) ];
endfunction;
function [y] = r21(x,m21,teta)
	y = m21*x + [ L/4*( sqrt(3) - m21 ) ];
endfunction;
function [y] = r31(x,m31,teta)
  y = m31*(x-L/2);
endfunction;
//--------------------------
function desenhaRn1()
  d = 3*L/4
  x = [d:0.01:5+d];
  y = feval(x,rn1)
  plot(x,y,'b')
endfunction;
function desenhaRn2()
  d = L/4
  x = [d:-0.01:-5+d];
  y = feval(x,rn2)
  plot(x,y,'b')
endfunction;
function desenhaRn3()
  y = [0:-0.01:-5]
  for i=1:length(y)
    x(i) = L/2
  end
  plot(x,y,'b')
endfunction;
//--------------------------
function desenhaR11(teta,c)
  x = [-4*L:0.04:4*L];
  m11 = tan(teta+atan(sqrt(3)/3))
  for i=1:length(x) do
    y(i) = r11(x(i),m11,teta);
  end;
  plot(x,y,c)
endfunction;
function desenhaR12(teta,c)
  teta = supr(teta)
  desenhaR11(teta,c)
endfunction;
//--------
function desenhaR21(teta,c)
  x = [-4*L:0.04:4*L];
  m21 = tan(teta+atan(-(sqrt(3)/3)))
  for i=1:length(x) do
    y(i) = r21(x(i),m21,teta);
  end;
  plot(x,y,c)
endfunction;
function desenhaR22(teta,c)
  teta = supr(teta)
  desenhaR21(teta,c)
endfunction;
//--------
function desenhaR31(teta,c)
  x = [-4*L:0.04:4*L];
  m31 = tan((%pi/2) + teta); 
  for i=1:length(x) do
    y(i) = r31(x(i),m31,teta);
  end;
  plot(x,y,c)
endfunction;
function desenhaR32(teta,c)
  teta = supr(teta)
  desenhaR31(teta,c)
endfunction;
//--------------------------
function desenhaEixos(t)
  x1 = [-t:0.1:t]
  y1 = zeros(1,length(x1))
  plot(x1,y1,'b')
  x2 = y1
  y2 = x1
  plot(x2,y2,'b')
endfunction
//--------------------------
function desenhaTriangulo()
  function [y] = lado1(x)
    y = -sqrt(3)*x + sqrt(3)*L
  endfunction
  function [y] = lado2(x)
    y = sqrt(3)*x
  endfunction

  x1 = [L/2:0.1:L]
  y1 = feval(x1,lado1)

  x2 = [0:0.1:L/2]
  y2 = feval(x2,lado2)
  plot(x1,y1,'b')
  plot(x2,y2,'b')

endfunction
//--------------------------
desenhaEixos(100)
desenhaTriangulo()
desenhaRn1()
desenhaRn2()
desenhaRn3()
desenhaR11(gr2rad(22.68288710964),'r')
desenhaR12(gr2rad(22.68288710964),'r')
desenhaR21(gr2rad(-61.3105004414),'g')
desenhaR22(gr2rad(-61.3105004414),'g')
desenhaR31(gr2rad(-29.4460409741),'b')
desenhaR32(gr2rad(-29.4460409741),'b')
//--------------------------

//--------------------------
